import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

let storage_toke = ''

try {
    storage_toke = uni.getStorageSync('token')?uni.getStorageSync('token'):'';
} catch (e) {
    // error
}

const store = new Vuex.Store({
	state: {
		baseUrl: 'https://api.zlkj-port.com', // 生产地址
		testUrl: 'http://localhost:9051',
		token: storage_toke, // jwt token
		userInfo: uni.getStorageSync('userInfo')||{},
		portArr: [],
		roleArr: [],
		activePort: '', // htg ykg dfg
		listDptUrl: 'https://api.zlkj-port.com/yqapi/ITally/xhtt/Q/q715TqlJXtFwCQq',
		listUserUrl: 'https://api.zlkj-port.com/yqapi/ITally/xhtt/Q/STxnufwkkAOwk5S',
		saveRecord: 'https://api.zlkj-port.com/yqapi/ITally/xhtt/A/tJFNhiXp4k1S4kI',
		listRecord: 'https://api.zlkj-port.com/yqapi/ITally/xhtt/Q/5d7TD40NzZyxkkk',
		listRecordStatus: 'https://api.zlkj-port.com/yqapi/ITally/xhtt/Q/TpI7eDZaf0562Ua',
		listUserRoles: 'https://api.zlkj-port.com/yqapi/ITally/xhtt/Q/STxnufwkkAOwk5S',
		listUserTel: 'https://api.zlkj-port.com/yqapi/ITally/xhtt/Q/7nGfLx6LYDNzuU8',
		listUserInfo: 'https://api.zlkj-port.com/tcapi/api/authorize/userinfo',
	},
	mutations: {
		login(state, provider) {
			
		},
		loginSuccess(state, provider) {
			state.userInfo = provider.userInfo
			// state.portArr = provider.userInfo.portName.split(',')
			// state.roleArr = provider.userInfo.roleName.split(',')
			uni.setStorage({//缓存用户登陆状态
			    key: 'userInfo',  
			    data: provider.userInfo 
			}) 
		},
		logout (state, provider) {
			uni.removeStorageSync('userInfo')
			state.userInfo = {}
			state.portArr = []
			state.roleArr = []
		},
		setActivePort (state, provider) {
			state.activePort = provider.activePort
		}
	},
	actions: {
	}
})

export default store
